/*
 * @Description: 
 * @Author: changqing
 * @Date: 2021-08-30 19:46:37
 * @LastEditTime: 2021-08-30 19:49:09
 * @LastEditors: changqing
 * @Usage: 
 */


//shareReplay可以直接当作是multicast(new ReplaySubject())与refCount()的组合，与share不同的是，shareReplay有重播的概念，也就是每次订阅时，会重播过去N次发生的数据
var { timer, interval,range,from,Subject } = require('rxjs'); 
var {take,map, multicast,publish,refCount,shareReplay} = require('rxjs/operators');

const source = interval(1000)
  .pipe(
        map((x) => {
            console.log('Processing: ', x);
            return x*x;
        }),
        shareReplay()
);

source.subscribe(x => console.log('subscription 1: ', x));
setTimeout(()=>{
  source.subscribe(x => console.log('subscription 2: ', x));
},3000)
